#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

class Solution {
	
public:
	int to_num(string &str){
		
		int nNum=0;
		int nIdx=0;
		if(str[0]=='-'){
			
			++nIdx;
		}
		for(int i=nIdx;i<static_cast<int>(str.size());++i){
			
			nNum=nNum*10+(str[i]-'0');
		}
		if(nIdx==1){
			
			nNum=-nNum;
		}
		return nNum;
	}
	int calculate(int nNum1,int nNum2,string sOp){
		
		if(sOp=="+"){
			
			return nNum1+nNum2;
		}
		else if(sOp=="-"){
			
			return nNum2-nNum1;
		}
		else if(sOp=="*"){
			
			return nNum1*nNum2;
		}
		else{
			
			return nNum2/nNum1;
		}
	}
    int evalRPN(vector<string>& tokens) {
        
        stack<int> st;
        for(int i=0;i<static_cast<int>(tokens.size());++i){
			
			if(tokens[i]=="+" || tokens[i]=="-" || tokens[i]=="*" || tokens[i]=="/"){
				
				int nNum1=st.top();
				st.pop();
				//cout<<nNum1<<' ';
				int nNum2=st.top();
				st.pop();
				//cout<<nNum2<<' ';
				int nRet=calculate(nNum1,nNum2,tokens[i]);
				//cout<<nRet<<endl;
				st.push(nRet);
			}
			else{
				
				st.push(to_num(tokens[i]));
			}
		}
		return st.top();
    }
};
